package io.lkt.modules.sys.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import io.lkt.common.util.Query;
import io.lkt.common.validator.ValidatorUtils;
import io.lkt.modules.sys.entity.BUserShieldEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.lkt.modules.sys.entity.BArticleShieldEntity;
import io.lkt.modules.sys.service.BArticleShieldService;
import io.lkt.common.utils.PageUtils;
import io.lkt.common.utils.R;



/**
 * 文章(换成我的)屏蔽表
 *
 * @author xss
 * @email dustwas@163.com
 * @date 2021-09-02 09:19:51
 */
@RestController
@RequestMapping("/sys/barticleshield")
public class BArticleShieldController {
    @Autowired
    private BArticleShieldService bArticleShieldService;

    @RequestMapping("/getList")
    public R getList(@RequestParam Map<String, Object> params) {
        Query query = new Query(params);
        List<BArticleShieldEntity> list = bArticleShieldService.getList(query);
        int total = bArticleShieldService.getListTotal(query).intValue();

        PageUtils page = new PageUtils(list, total, query.getLimit(), query.getPage());
        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:barticleshield:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bArticleShieldService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:barticleshield:info")
    public R info(@PathVariable("id") Integer id){
        BArticleShieldEntity bArticleShield = bArticleShieldService.getById(id);

        return R.ok().put("bArticleShield", bArticleShield);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("sys:barticleshield:save")
    public R save(@RequestBody BArticleShieldEntity bArticleShield){
        bArticleShieldService.saveInfo(bArticleShield);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:barticleshield:update")
    public R update(@RequestBody BArticleShieldEntity bArticleShield){
        ValidatorUtils.validateEntity(bArticleShield);
        bArticleShieldService.updateById(bArticleShield);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:barticleshield:delete")
    public R delete(@RequestBody Integer[] ids){
        bArticleShieldService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 根据文章 ID 获取换成我的信息
     * @param articleId 文章 ID
     * @return
     */
    @RequestMapping("/articleInfo/{articleId}")
    public R articleInfo(@PathVariable("articleId") Integer articleId){
        BArticleShieldEntity bArticleShield = bArticleShieldService.getByArticleId(articleId);

        return R.ok().put("bArticleShield", bArticleShield);
    }

    @RequestMapping("/deleteByArticleId/{articleId}")
    public R deleteByArticleId(@PathVariable("articleId") Integer articleId) {
        bArticleShieldService.deleteByArticleId(articleId);
        return R.ok();
    }

}
